package com.example.swd1.gudong.base;

import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toolbar;

import com.example.swd1.gudong.R;
import com.example.swd1.gudong.constant.Constant;

import java.util.ArrayList;
import java.util.List;


//==================================================================================================================
//   Author :  Shile Wu
//   Date  :  16-8-23
//   Role :  encapsulation some activity operations
//   Reference documents : None
//==================================================================================================================
public class BaseFragmentActivity extends FragmentActivity {
    /*
    * the views in toolbar
    * */
    private Toolbar toolbar;
    private TextView titleTextView;
    private TextView  settingTextView, orderFormTextView, kabiTextView, contactsTextView, dynamicText, squareText;
    private ImageView addFriendsImg, searchImg, runImg, settingImg, scanImg, cameraImg, indicatorDot1Img, indicatorDot2Img, indicatorDot3Img;
    private List<View> toolBarViewList;
    private View dynamicLineImg, squareLineImg;

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        initView();

        if (toolbar != null) {
            toolbar.setTitle("");
            setActionBar(toolbar);
        }
    }

    private void initView(){
        toolbar = (Toolbar) findViewById(R.id.head_layout);

        titleTextView = (TextView) findViewById(R.id.tool_bar_title);
        settingTextView = (TextView) findViewById(R.id.text_setting);
        orderFormTextView = (TextView) findViewById(R.id.text_order_form);
        kabiTextView = (TextView) findViewById(R.id.text_kabi);
        contactsTextView = (TextView) findViewById(R.id.text_contacts);
        addFriendsImg = (ImageView) findViewById(R.id.menu_add_friends_img);
        searchImg = (ImageView) findViewById(R.id.menu_search_img);
        runImg = (ImageView) findViewById(R.id.menu_run_img);
        settingImg = (ImageView) findViewById(R.id.menu_setting_img);
        scanImg = (ImageView) findViewById(R.id.menu_scan_img);
        cameraImg = (ImageView) findViewById(R.id.menu_camera_img);
        indicatorDot1Img = (ImageView) findViewById(R.id.indicator_dot1);
        indicatorDot2Img = (ImageView) findViewById(R.id.indicator_dot2);
        indicatorDot3Img = (ImageView) findViewById(R.id.indicator_dot3);
        dynamicText = (TextView) findViewById(R.id.text_dynamic);
        squareText = (TextView) findViewById(R.id.text_square);
        dynamicLineImg = findViewById(R.id.line_dynamic);
        squareLineImg = findViewById(R.id.line_square);


        toolBarViewList = new ArrayList<View>();
        toolBarViewList.add(addFriendsImg);
        toolBarViewList.add(searchImg);
        toolBarViewList.add(runImg);
        toolBarViewList.add(contactsTextView);
        toolBarViewList.add(settingTextView);
        toolBarViewList.add(orderFormTextView);
        toolBarViewList.add(kabiTextView);
        toolBarViewList.add(settingImg);
        toolBarViewList.add(scanImg);
        toolBarViewList.add(cameraImg);
        toolBarViewList.add(indicatorDot1Img);
        toolBarViewList.add(indicatorDot2Img);
        toolBarViewList.add(indicatorDot3Img);
        toolBarViewList.add(dynamicText);
        toolBarViewList.add(squareText);
        toolBarViewList.add(dynamicLineImg);
        toolBarViewList.add(squareLineImg);
    }

    public void setTitle(String title) {
        titleTextView.setText(title);
    }

    public void setTitleSize(float size) {
        titleTextView.setTextSize(size);
    }

    /*
    *show and hide menu according to difference fragment
    * */
    public void showSportRangMenu() {
        toolbar.setVisibility(View.VISIBLE);
        for (View view : toolBarViewList) {
            if (addFriendsImg == view) {
                view.setVisibility(View.VISIBLE);
            } else if (cameraImg == view) {
                view.setVisibility(View.VISIBLE);
            } else {
                view.setVisibility(View.INVISIBLE);
            }
        }
    }

    public void showSportRangTitle(int flag) {
        toolbar.setVisibility(View.VISIBLE);
        dynamicText.setVisibility(View.VISIBLE);
        squareText.setVisibility(View.VISIBLE);
        if (flag == Constant.VIEW_PAGE_FLAG_DYNAMIC) {
            dynamicLineImg.setVisibility(View.VISIBLE);
            squareLineImg.setVisibility(View.INVISIBLE);
            dynamicText.setTextColor(getResources().getColor(R.color.white));
            squareText.setTextColor(getResources().getColor(R.color.codoon_hint));
        } else {
            squareLineImg.setVisibility(View.VISIBLE);
            dynamicLineImg.setVisibility(View.INVISIBLE);
            dynamicText.setTextColor(getResources().getColor(R.color.codoon_hint));
            squareText.setTextColor(getResources().getColor(R.color.white));
        }
    }

    public void showFoundMenu() {
        toolbar.setVisibility(View.VISIBLE);
        for (View view : toolBarViewList) {
            if (searchImg == view) {
                view.setVisibility(View.VISIBLE);
            } else if (scanImg == view) {
                view.setVisibility(View.VISIBLE);
            } else {
                view.setVisibility(View.INVISIBLE);
            }
        }
    }

    public void showSportMenu(int flag) {
        toolbar.setVisibility(View.VISIBLE);
        for (View view : toolBarViewList) {
            if (runImg == view) {
                view.setVisibility(View.VISIBLE);
            } else if (settingImg == view) {
                view.setVisibility(View.VISIBLE);
            } else if (view == indicatorDot1Img || view == indicatorDot2Img || view == indicatorDot3Img) {
                view.setVisibility(View.VISIBLE);
                if (flag == Constant.VIEW_PAGE_FLAG_SPORT) {
                    runImg.setVisibility(View.VISIBLE);
                    indicatorDot1Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_normal));
                    indicatorDot2Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_selected));
                    indicatorDot3Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_selected));
                } else if (flag == Constant.VIEW_PAGE_FLAG_TRAIN) {
                    runImg.setVisibility(View.INVISIBLE);
                    indicatorDot1Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_selected));
                    indicatorDot2Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_normal));
                    indicatorDot3Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_selected));
                } else if (flag == Constant.VIEW_PAGE_FLAG_TARGET) {
                    runImg.setVisibility(View.VISIBLE);
                    indicatorDot1Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_selected));
                    indicatorDot2Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_selected));
                    indicatorDot3Img.setImageDrawable(getResources().getDrawable(R.drawable.ic_viewpage_point_w_normal));
                }
            } else {
                view.setVisibility(View.INVISIBLE);
            }
        }
    }

    public void showMessageMenu() {
        toolbar.setVisibility(View.VISIBLE);
        for (View view : toolBarViewList) {
            if (contactsTextView == view) {
                view.setVisibility(View.VISIBLE);
            } else {
                view.setVisibility(View.INVISIBLE);
            }
        }
    }

    public void showUserMenu() {
        toolbar.setVisibility(View.GONE);
//        for (View view : toolBarViewList) {
//            if (kabiTextView == view) {
//                view.setVisibility(View.VISIBLE);
//            } else if (orderFormTextView == view) {
//                view.setVisibility(View.VISIBLE);
//            } else if (settingTextView == view) {
//                view.setVisibility(View.VISIBLE);
//            } else {
//                view.setVisibility(View.GONE);
//            }
//        }
    }

    public List<View> getToolBarViewList() {
        return toolBarViewList;
    }


    public void hideHeadLayout(){
        toolbar.setVisibility(View.GONE);
    }
    public void showHeadLayout(){
        toolbar.setVisibility(View.VISIBLE);
    }
}